const Redis = require('../../middleware/redis')

module.exports = {
  sign(_id,date, time, result) {   
    if(result) {
      Redis.del('token' + result.split('.')[0])
    } 
    const token = date + '.' + _id + '.' +  Date.now()
    // 存入token
    Redis.set('token' + date, token, time)
    // 返回token,用来传给前端
    return token
  },
  
  expire(key, time) {
    Redis.expire(key, time)
  },
  async verify(date) {
    // 通过sessionID获取到token,然后返回出去
    return await Redis.get('token' + date)
  }  
}

